package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.aop.PassToken;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.BaseShopSearch;
import net.pinnoocle.playdao.entity.shopPc.master.*;
import net.pinnoocle.playdao.entity.web.master.*;
import net.pinnoocle.playservice.service.impl.MasterServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-10-25 11:20
 */
@RestController
@RequestMapping("/master")
@Api(tags = "主持人管理")
public class MasterController {
    @Autowired
    MasterServiceImpl masterService;

    @GetMapping("shopMasterList")
    @ApiOperation("DM管理列表")
    public BaseResult<PageModel<MasterListPageVo>> shopMasterList(MasterListSearchParams searchParams){
        return new BaseResult<PageModel<MasterListPageVo>>().ok(masterService.shopMasterList(searchParams));
    }

    @GetMapping("freeMasterList")
    @ApiOperation("空闲主持人列表")
    public BaseResult<List<WebMasterListPageVo>> freeMasterList(@RequestParam("scriptId") String scriptId){
        return new BaseResult<List<WebMasterListPageVo>>().ok(masterService.freeMasterList(scriptId));
    }

    @GetMapping("masterDetail")
    @ApiOperation("主持人详情")
    @PassToken
    public BaseResult<WebMasterDetailVo> masterDetail(@RequestParam("masterId") String masterId,
                                                      @RequestParam(name = "page") Integer page,
                                                      @RequestParam(name = "pageSize") Integer pageSize){
        return new BaseResult<WebMasterDetailVo>().ok(masterService.masterDetail(masterId,page,pageSize));
    }

    @PostMapping("shopUpdateMaster")
    @ApiOperation("店铺编辑DM部分信息")
    public BaseResult<String> shopUpdateMaster(@Validated @RequestBody UpdateMasterParams params){
        boolean result = masterService.shopUpdateMaster(params);
        if(result){
            return new BaseResult<String>().success("编辑DM信息成功");
        }
        return new BaseResult<String>().error("编辑DM信息失败");
    }

    @GetMapping("shopWaitCheckMasterList")
    @ApiOperation("待审核DM列表")
    public BaseResult<PageModel<CheckMasterListPageVo>> shopWaitCheckMasterList(WaitCheckMasterSearchParams searchParams){
        return new BaseResult<PageModel<CheckMasterListPageVo>>().ok(masterService.shopWaitCheckMasterList(searchParams));
    }

    @GetMapping("shopCheckPass")
    @ApiOperation("店铺审核DM")
    public BaseResult<String> shopCheckPass(@RequestParam("masterId") String masterId,
                                            @RequestParam("check") Integer check){
        boolean result = masterService.shopCheckPass(masterId,check);
        if(result){
            return new BaseResult<String>().success("操作成功");
        }
        return new BaseResult<String>().error("操作失败");
    }

    @GetMapping("scriptList")
    @ApiOperation("DM会的本")
    public BaseResult<PageModel<WebMasterScriptListPage>> masterScriptList(@RequestParam("masterId") String masterId,
                                                                           @RequestParam("page") Integer page,
                                                                           @RequestParam("pageSize") Integer pageSize){
        PageModel<WebMasterScriptListPage> pageList = masterService.masterAbleScriptList(masterId,page, pageSize);
        return new BaseResult<PageModel<WebMasterScriptListPage>>().ok(pageList);
    }

    @GetMapping("masterFinance")
    @ApiOperation("DM收入明细 yearMonth：2021-11 不传默认当前月")
    public BaseResult<MasterShopFinanceVo> masterFinance(@RequestParam("masterId") String masterId,
                                                         @RequestParam(name = "yearMonth",required = false) String yearMonth){
        return new BaseResult<MasterShopFinanceVo>().ok(masterService.shopMasterFinanceVo(masterId,yearMonth));
    }

    @GetMapping("leftSalary")
    @ApiOperation("DM剩余未结算工资")
    public BaseResult<Double> leftSalary(@RequestParam("masterId") String masterId){
        return new BaseResult<Double>().ok(masterService.leftSalary(masterId));
    }



    @GetMapping("dismissMaster")
    @ApiOperation("解雇主持人")
    public BaseResult<String> dismissMaster(@RequestParam("masterId") String masterId){
        boolean result = masterService.dismissMaster(masterId);
        if(result){
            return new BaseResult<String>().success("解雇成功");
        }
        return new BaseResult<String>().error("解雇失败");
    }

    @GetMapping("cleanMasterSalary")
    @ApiOperation("结清主持人工资")
    public BaseResult<String> cleanMasterSalary(@RequestParam("masterId") String masterId){
        boolean result = masterService.cleanMasterSalary(masterId);
        if(result){
            return new BaseResult<String>().success("结清成功");
        }
        return new BaseResult<String>().error("结清失败");
    }


    @GetMapping("masterWithdrawList")
    @ApiOperation("主持人申请提现列表")
    public BaseResult<PageModel<MasterWithdrawListPageVo>> masterWithdrawList(MasterWithdrawSearchParams params){
        return new BaseResult<PageModel<MasterWithdrawListPageVo>>().ok(masterService.shopMasterWithdrawList(params));
    }


    @GetMapping("masterWithdrawListCheck")
    @ApiOperation("提现审核---1 审核通过 2拒绝")
    public BaseResult<String> masterWithdrawListCheck(@RequestParam("withdrawId") String withdrawId,
                                                      @RequestParam("isCheck") Integer isCheck,
                                                      @RequestParam(name = "refuseReason",required = false) String refuseReason){
        boolean result = masterService.masterWithdrawListCheck(withdrawId,isCheck,refuseReason);
        if(result){
            return new BaseResult<String>().success("提现审核成功");
        }
        return new BaseResult<String>().error("提现审核失败");
    }
}
